package com.example.pkmedical.Activity.weight.options;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.pkmedical.APP.MyApp;
import com.example.pkmedical.Base.BaseActivity;
import com.example.pkmedical.R;
import com.example.pkmedical.Utils.CommandUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OptionsHomeActivity extends BaseActivity {

    @BindView(R.id.main_house)
    ImageView mainHouse;
    @BindView(R.id.main_house_text)
    TextView mainHouseText;
    @BindView(R.id.weight_home_adjustment_bt)
    Button weightHomeAdjustmentBt;
    @BindView(R.id.option_home_add_button)
    Button optionHomeAddButton;
    @BindView(R.id.option_home_company_layout)
    RelativeLayout optionHomeCompanyLayout;
    @BindView(R.id.option_company_text)
    TextView optionCompanyText;
    @BindView(R.id.optionhome_back_button)
    Button optionhomeBackButton;
    private PopupWindow CompanyPop;
    private boolean companyType = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_optionshome);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        switch (CommandUtil.COMPANY_TYPE) {
            case 0:
                optionCompanyText.setText(R.string.kg);
                break;
            case 1:
                optionCompanyText.setText(R.string.bang);
                break;
        }
    }

    @Override
    public void initView() {
        mainHouse.setImageResource(R.drawable.img_title_weight);
        mainHouseText.setText(R.string.title_weight);
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void showDialog(String... msg) {

    }

    @OnClick({R.id.optionhome_back_button, R.id.weight_home_adjustment_bt, R.id.option_home_add_button, R.id.option_home_company_layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.weight_home_adjustment_bt:
                startActivity(new Intent(MyApp.getAppContext(), OptionChangeWeightActivity.class));
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
                break;
            case R.id.option_home_add_button:
                startActivity(new Intent(MyApp.getAppContext(), OptionAddActivity.class));
//                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
                break;
            case R.id.option_home_company_layout:
                initCefanWindow();
                break;
            case R.id.optionhome_back_button:
                finish();
                break;
        }
    }

    /**
     * 选择器
     */
    private void initCefanWindow() {
        View view = LayoutInflater.from(this).inflate(R.layout.item_option_company, null);
        RelativeLayout kg = view.findViewById(R.id.company_item_kg);
        RelativeLayout bang = view.findViewById(R.id.company_item_bang);
        switch (CommandUtil.COMPANY_TYPE) {
            case 0:
                kg.setVisibility(View.GONE);
                break;
            case 1:
                bang.setVisibility(View.GONE);
                break;
        }

        kg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                optionCompanyText.setText(R.string.kg);
                companyType = true;
                CompanyPop.dismiss();
                CommandUtil.COMPANY_TYPE = 0;
            }
        });
        bang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                optionCompanyText.setText(R.string.bang);
                companyType = false;
                CompanyPop.dismiss();
                CommandUtil.COMPANY_TYPE = 1;
            }
        });
        CompanyPop = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        CompanyPop.setFocusable(true);
        CompanyPop.setOutsideTouchable(true);
        CompanyPop.setBackgroundDrawable(new ColorDrawable());
        CompanyPop.showAsDropDown(optionHomeCompanyLayout);

    }
}
